#!/bin/bash


#
# Flow stability for dynamic community detection https://arxiv.org/abs/2101.06131v2
#
# Copyright (C) 2021 Alexandre Bovet <alexandre.bovet@maths.ox.ac.uk>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


# script to perform the clustering of the hierarchical example (Fig. 3)



BATCHNUM=$1

JNAME="synthnet_paper_example_${BATCHNUM}"

NETFILENAME="hiera_tempnet_paper_${BATCHNUM}"

RUNDIR="$HOME/rundir"

DATADIRBASE="$HOME/datadir"

mkdir -p $DATADIRBASE

LAPINTERTRANSDIR="$DATADIRBASE/lapl_intertransmat_${BATCHNUM}"

INTEGDIR="$DATADIRBASE/integralgrid_${BATCHNUM}"

CLUSTSDIRI="$DATADIRBASE/clustersI_${BATCHNUM}"

mkdir -p $LAPINTERTRANSDIR
mkdir -p $CLUSTSDIRI
mkdir -p $INTEGDIR


CLUSTNUMREPEAT=50

NETNAME="synthtemp_hiera_paper_example_${BATCHNUM}"

# laplacians and transition matrices resolution grid
NUM_SLICES=40
INT_LENGTH=1


NCPU=1


TAUWS=(0.01 75 1000 2000)

 
# compute laplacians and intertransition matrices
python3 -u $RUNDIR/run_laplacians_transmat.py \
        --datadir $DATADIRBASE \
        --savedir $LAPINTERTRANSDIR \
        --net_filename $NETFILENAME \
        --net_name $NETNAME \
        --save_slice_trans \
        --ncpu $NCPU \
        --tau_w_list ${TAUWS[*]} \
        --save_inter_T \
        --num_slices $NUM_SLICES \
        --t0 0.0 \
        --tend 1000 \
        > output_${JNAME}_lptm.txt 2> error_${JNAME}_lptm.txt

        
# compute autocov_grid 
python3 -u $RUNDIR/make_sparse_autocov_integral.py \
        --datadir $LAPINTERTRANSDIR \
        --savedir $INTEGDIR \
        --net_name $NETNAME \
        --int_length $INT_LENGTH \
        --time_direction "forward" \
        --ncpu $NCPU \
        --only_expm_transmats \
        --only_from_start \
        --verbose \
        > output_${JNAME}_expm_intg.txt 2> error_${JNAME}_expm_intg.txt

        
# compute clustering of integral
python3 -u $RUNDIR/run_sparse_clustering.py \
        --datadir $INTEGDIR \
        --savedir $CLUSTSDIRI \
        --ncpu $NCPU \
        --num_repeat $CLUSTNUMREPEAT \
        --net_name $NETNAME \
        > output_${JNAME}_clust.txt 2> error_${JNAME}_clust.txt



